package cn.niit.service.impl;

import cn.niit.dao.CourseDao;
import cn.niit.entity.Course;
import cn.niit.entity.Teacher;
import cn.niit.entity.query.CourseQuery;
import cn.niit.service.CourseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程基本信息表(Course)表服务实现类
 *
 * @author makejava
 * @since 2021-11-14 16:06:33
 */
@Service("courseService")
public class CourseServiceImpl implements CourseService {
    @Resource
    private CourseDao courseDao;


    @Override
    public PageInfo<Course> queryByCourse(CourseQuery courseQuery) {
        PageHelper.startPage(courseQuery.getPageNum(), courseQuery.getPageSize());
        return new PageInfo<Course>(courseDao.queryByCourse(courseQuery));
    }

    @Override
    public PageInfo<Course> queryByCourseName(CourseQuery courseQuery) {
        PageHelper.startPage(courseQuery.getPageNum(), courseQuery.getPageSize());
        return new PageInfo<Course>(courseDao.queryByCourseName(courseQuery));
    }

    /**
     * 查询所有课程信息
     *
     * @return
     */
    @Override
    public List<Course> queryAllCourseList() {
        return courseDao.queryByCourse(null);
    }

    @Override
    public PageInfo<Course> select(CourseQuery courseQuery) {
        PageHelper.startPage(courseQuery.getPageNum(), courseQuery.getPageSize());
        return new PageInfo<Course>(courseDao.select(courseQuery));
    }

    @Override
    public boolean editCourse(Course course) {
        int i = courseDao.editCourse(course);
        return i > 0;
    }

    @Override
    public Course queryCourseById(Integer id) {
        return courseDao.queryCourseById(id);
    }

    @Override
    public boolean addCourse(Course course) {
        return courseDao.addCourse(course) > 0;
    }

    @Override
    public boolean deleteCourseById(Integer id) {
        int i = courseDao.deleteCourseById(id);
        return i > 0;
    }
}